package GUILayer;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.util.HashMap;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 * MainFrame. 
 * This class is the entrypoint for starting the program.
 * It contains a JTabbedPane that contains the LoginGUI and userframes (panels) when the users log in.
 * All userGUIs is stored in hashmaps on the mainframe.
 * All userPanels is also stored in hashmaps on the mainframe.
 * 31.05.2012
 * @author Lindgren
 * @Version 0.1
 */
public class MainFrame {

	private static MainFrame instance;

	private static JFrame frmTheIrishHouse; // MainFrame!

	private static Dimension scrnsize = Toolkit.getDefaultToolkit().getScreenSize();

	private static JTabbedPane tabbedPane; 

	private static LoginGUI loginGUI; //

	private static HashMap<String, UserFrame> userFrames = new HashMap<String, UserFrame>();
	private static HashMap<String, MainGUI> mainGUIs = new  HashMap<String, MainGUI>();
	private static HashMap<String, SaleGUI> saleGUIs = new HashMap<String, SaleGUI>();
	private static HashMap<String, PaymentGUI> paymentGUIs = new HashMap<String, PaymentGUI>();
	private static HashMap<String, DraughtBeerGUI> draughtBeerGUIs = new HashMap<String, DraughtBeerGUI>();
	private static HashMap<String, BottledBeerGUI> bottledBeerGUIs = new HashMap<String, BottledBeerGUI>();
	private static HashMap<String, EventGUI> eventGUIs = new HashMap<String, EventGUI>();

	private static HashMap<String, JPanel> userFramePanels = new HashMap<String, JPanel>(); 
	private static HashMap<String, JPanel> mainGUIPanels = new HashMap<String, JPanel>();
	private static HashMap<String, JPanel> saleGUIPanels = new HashMap<String, JPanel>();
	private static HashMap<String, JPanel> paymentGUIPanels = new HashMap<String, JPanel>();
	private static HashMap<String, JPanel> draughtBeerGUIPanels = new HashMap<String, JPanel>();
	private static HashMap<String, JPanel> bottledBeerGUIPanels = new HashMap<String, JPanel>();

	private static HashMap<String, JPanel> eventGUIPanels = new HashMap<String, JPanel>();


	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {

					MainFrame window = MainFrame.getInstance();
					System.out.println("MainFrame window created: "+window);

					loginGUI = LoginGUI.getInstance();
					System.out.println("MainFrame loginGUI retrieved: "+loginGUI);
					System.out.println("MainFrame Created!");
					System.out.println("");

				} catch (Exception e) {

					e.printStackTrace();
					System.err.println("Loading MainFrame Failed!");					
				}
			}
		});
	}

	/**
	 * Singleton getInstance.
	 */
	public static MainFrame getInstance()
	{
		if(instance==null)
		{
			instance = new MainFrame();
		}
		System.out.println("MainFrame getInstance returned: "+instance);
		return instance;
	}

	/**
	 * Create the application.
	 * Creating the main frame frmTheIrishHouse.
	 */
	private MainFrame() {

		System.out.println("Creating MainFrame Please Wait");
		
		frmTheIrishHouse = new JFrame();
		System.out.println("MainFrame frmTheIrishHouse created: "+frmTheIrishHouse);	

		frmTheIrishHouse.setTitle("The Irish House");
		System.out.println("MainFrame frmTheIrishHouse title set: "+frmTheIrishHouse.getTitle());

		frmTheIrishHouse.setSize(scrnsize);					
		System.out.println("MainFrame frmTheIrishHouse scrnsize set: "+scrnsize);

		frmTheIrishHouse.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		System.out.println("MainFrame frmTheIrishHouse DefaultCloseOperation set: "+frmTheIrishHouse.getDefaultCloseOperation());

		frmTheIrishHouse.getContentPane().setLayout(null);
		System.out.println("MainFrame frmTheIrishHouse layout set: "+frmTheIrishHouse.getContentPane().getLayout());

		frmTheIrishHouse.setLayout(new GridLayout(0, 1, 0, 0));

		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		System.out.println("MainFrame tabbedPane created: "+tabbedPane);

		frmTheIrishHouse.getContentPane().add(tabbedPane);
		System.out.println("MainFrame tabbedPane added: "+tabbedPane);

		// Set full screen mode.
		setFullScreenMode();

		frmTheIrishHouse.setVisible(true);
		System.out.println("MainFrame setVisible: "+true);	
	}

	/**
	 * @return the scrnsize
	 */
	public static Dimension getScrnsize() {
		return scrnsize;
	}

	/**
	 * @param scrnsize, the scrnsize to use
	 */
	public static void setScrnsize(Dimension scrnsize) {
		MainFrame.scrnsize = Toolkit.getDefaultToolkit().getScreenSize();
	}

	/**
	 * @return the tabbedPane
	 */
	public static JTabbedPane getTabbedPane() {
		return tabbedPane;
	}

	/**
	 * @return the frmTheIrishHouse
	 */
	public static JFrame getFrmTheIrishHouse() {
		return frmTheIrishHouse;
	}

	/**
	 * @return the userGUIPanels
	 */
	public static HashMap<String, JPanel> getUserFramePanels() {
		return userFramePanels;
	}

	/**
	 * @return the mainGUIPanels
	 */
	public static HashMap<String, JPanel> getMainGUIPanels() {
		return mainGUIPanels;
	}

	/**
	 * @return the saleGUIPanels
	 */
	public static HashMap<String, JPanel> getSaleGUIPanels() {
		return saleGUIPanels;
	}

	/**
	 * @return the paymentGUIPanels
	 */
	public static HashMap<String, JPanel> getPaymentGUIPanels() {
		return paymentGUIPanels;
	}

	/**
	 * @return the draughtBeerGUIPanels
	 */
	public static HashMap<String, JPanel> getDraughtBeerGUIPanels() {
		return draughtBeerGUIPanels;
	}

	/**
	 * @return the userGUIHolders
	 */
	public static HashMap<String, UserFrame> getUserFrames() {
		return userFrames;
	}

	/**
	 * @return the eventGUIPanels
	 */
	public static HashMap<String, JPanel> getEventGUIPanels() {
		return eventGUIPanels;
	}

	/**
	 * @return the saleGUIs
	 */
	public static HashMap<String, SaleGUI> getSaleGUIs() {
		return saleGUIs;
	}

	/**
	 * @return the mainGUIs
	 */
	public static HashMap<String, MainGUI> getMainGUIs() {
		return mainGUIs;
	}

	/**
	 * @return the paymentGUIs
	 */
	public static HashMap<String, PaymentGUI> getPaymentGUIs() {
		return paymentGUIs;
	}

	/**
	 * @return the draughtBeerGUIs
	 */
	public static HashMap<String, DraughtBeerGUI> getDraughtBeerGUIs() {
		return draughtBeerGUIs;
	}

	/**
	 * @return the eventGUIs
	 */
	public static HashMap<String, EventGUI> getEventGUIs() {
		return eventGUIs;
	}

	/**
	 * @return the bottledBeerGUIPanels
	 */
	public static HashMap<String, JPanel> getBottledBeerGUIPanels() {
		return bottledBeerGUIPanels;
	}

	/**
	 * @return the bottledBeerGUIs
	 */
	public static HashMap<String, BottledBeerGUI> getBottledBeerGUIs() {
		return bottledBeerGUIs;
	}

	/**
	 * changes view to full screen
	 */
	private void setFullScreenMode() {
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice gs = ge.getDefaultScreenDevice();
		if (gs.isFullScreenSupported()) {
			System.out.println("Full-screen mode is supported");
		} 
		else {
			System.out.println("Full-screen mode will be simulated");
		}
		gs.setFullScreenWindow(frmTheIrishHouse);
		frmTheIrishHouse.validate();

	}



}


